<template>
  <!--     @ok="handleOk" -->
  <div>
    <j-modal
      :title="title"
      :width="1000"
      :visible="visible"
      :confirmLoading="confirmLoading"
      switchFullscreen
      @cancel="handleCancel"
      cancelText="关闭"
      :okButtonProps="{ style: { display: 'none' } }"
      destroyOnClose
    >
      <a-spin :spinning="confirmLoading">
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSourceGS(dataSource)"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          @change="handleTableChange"
        >
          <span slot="action" slot-scope="text, record">
            <a @click="serverCoach(record)">编辑</a>
          </span>
        </a-table>
      </a-spin>
    </j-modal>
    <a-modal title="发配会员卡" v-model="visibles" @ok="handleOks" :confirm-loading="confirmLoadings">
      <a-form-model ref="ruleForm" :model="paramsDate" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item
          ref="cardNum"
          label="发配数量："
          prop="cardNum"
          :rules="[{ required: true, message: '请输入发配数量', trigger: 'change' }]">
          <a-input v-model="paramsDate.cardNum" /> 
        </a-form-model-item>
      </a-form-model>
    </a-modal>
  </div>
</template>

<script>
import { httpAction, getFileAccessHttpUrl } from '@/api/manage'
import Area from '@/components/_util/Area'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import moment from 'moment'
export default {
  name: 'XhdjCoachInfoDialog',
  mixins: [JeecgListMixin],
  data() {
    return {
      title: '操作',
      visible: false,
      visibles: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      coachId: '',
      paramsDate: {},
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '分销商名称',
          align: 'center',
          dataIndex: 'distributionName',
        },
        {
          title: '分销商电话',
          align: 'center',
          dataIndex: 'distributionPhone',
        },
        // 0- 广告商  1-公司员工
        {
          title: '分销商类型',
          align: 'center',
          dataIndex: 'type',
          customRender: (text, record) => {
            return record.type == '1' ? '公司员工' : '广告商'
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 80,
          scopedSlots: { customRender: 'action' },
        },
      ],
      confirmLoading: false,
      confirmLoadings:false,
      dataSource: [],
      validatorRules: {},
      url: {
        list: '/xhdjDistribution/list',
        add: '/xhdjUserActivityBalanceRecord/addUserActivityBalanceRecord',
        delete: 'xhdjServerCoachLink/delete',
      },
      all: [], // 地址信息
      allList: [], // 省份数据
      citys: [],
      cityss: [],
    }
  },
  created() {
    this.all = new Area().all
    this.allList = this.all.filter((res) => res.index == 1)
  },
  methods: {
    handleOks() {
      this.confirmLoadings = true
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          httpAction(this.url.add, this.paramsDate, 'post').then((res) => {
            if (res.success) {
              this.visibles = false,
              this.confirmLoadings = false
              this.$message.success(res.message)
            } else {
              this.$message.warning(res.message)
            }
          })
        } else {
        }
      })
    },
    dataSourceGS(val) {
      return val.filter((res) => res.type !== 1)
    },
    uploadAction() {
      return window._CONFIG['domianURL'] + this.url.upload
    },
    getAvatarView: function (avatar) {
      return getFileAccessHttpUrl(avatar)
    },
    add() {
      //初始化默认值
      this.edit({})
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
      this.paramsDate = {
        activityBalanceCardId: this.coachId,
        distributionId: selectedRowKeys,
      }
    },
    getCheckboxProps(record) {
      return {
        props: {
          disabled: record.xhdjServerCoachLinkId != null,
        },
      }
    },
    edit(id) {
      this.coachId = id
      // this.queryParam.coachId = record.id
      this.loadData()
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    // 批量操作
    serverCoach(val) {
      this.paramsDate = {
        activityBalanceCardId: this.coachId.id,
        distributionId: val.id,
      }
      this.visibles = true
    },

    handleCancel() {
      this.close()
    },
  },
}
</script>

<style lang="less" scoped></style>
